package com.events
{
	import flash.errors.IOError;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.setTimeout;

	public class SaveXML
	{
		public function SaveXML(xmlData:XML,userid:String):void
		{
			var reqwest:URLRequest = new URLRequest("/assets/php/send.php");
			reqwest.method = URLRequestMethod.POST;
			var myVar:URLVariables = new URLVariables();
			myVar.xmlData = xmlData;
			myVar.userid = userid;
			reqwest.data = myVar;
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError); 
			loader.addEventListener(Event.COMPLETE, onComplete);
			trace (xmlData.rates);
			trace ("userid = " + userid);
			
			try 
			{ 
				loader.load(reqwest); 
			}
			catch (error:IOError) 
			{ 
				trace ("error:" + error); 
			}
			setTimeout(toMainState,1000);
		}
		
		private function toMainState():void
		{
			trace ('to main stage');
			
		}
		
		public function onIOError(evt:IOErrorEvent ):void 
		{ 
			trace("There was an IO Error." + evt); 
		} 
		
		public function onComplete(evt:Event):void 
		{ 
			trace("File was successfully saved."); 
			
		} 
		
		
	}
}